import Token
import Editor
import WordExpand
import string
import CmdNo
from Register import RegisterKeys
def InitKeymap(kh,viewtype='TextView'):
	InitStandardKeymap(kh)
	InitSmartWhitespaceKeymap(kh)
	kh.BindKey("C-Space",kh.SetSelStart)

def InitSmartWhitespaceKeymap(kh):
	#kh.BindKey("C-Space",kh.SetSelStart)
	kh.BindKey("Tab",Editor.SmartTab)
	kh.BindKey("Backspace",Editor.SmartBackspace)
	kh.BindKey("Del",Editor.SmartDelete)
	kh.BindKey("Space",Editor.SmartSpace)
	kh.BindKey("Left",Editor.SmartLeft)
	kh.BindKey("Right",Editor.SmartRight)

def InitStandardKeymap(kh):
	# Cursor movement
#	kh.BindKey("Down",Editor.Down)
#	kh.BindKey("Up",Editor.Up)
#	kh.BindKey("Right",Editor.Right)
#	kh.BindKey("Left",Editor.Left)

	# windows like shortcuts
	kh.BindKey("S-Del",Editor.Cut)
	kh.BindKey("C-Insert",Editor.Copy)
	kh.BindKey("S-Insert",Editor.Paste)

#	kh.BindKey("PageDown",Editor.GotoPageDown)
#	kh.BindKey("PageUp",Editor.GotoPageUp)
#	kh.BindKey("S-PageDown",Editor.SelectPageDown)
#	kh.BindKey("S-PageUp",Editor.SelectPageUp)

	kh.BindKey("C-n",Editor.Down)
	kh.BindKey("C-w",Editor.SelectWord)
	kh.BindKey("C-p",Editor.Up)
	kh.BindKey("C-f",Editor.Right)
	kh.BindKey("C-b",Editor.Left)

	kh.BindKey("C-N",Editor.SelectNextLine)
	kh.BindKey("C-P",Editor.SelectPrevLine)
	kh.BindKey("C-F",Editor.SelectNext)
	kh.BindKey("C-B",Editor.SelectPrev)

	kh.BindKey("Esc b",Editor.GotoWordStart)
	kh.BindKey("Esc f",Editor.GotoWordEnd)
	kh.BindKey("Esc B",Editor.SelectPrevWord)
	kh.BindKey("Esc F",Editor.SelectNextWord)

	kh.BindKey("C-a",Editor.GotoLineStart)
	kh.BindKey("C-e",Editor.GotoLineEnd)
	kh.BindKey("C-A",Editor.SelectLineStart)
	kh.BindKey("C-E",Editor.SelectLineEnd)


	kh.BindKey("F35",Editor.GotoPageDown)
	kh.BindKey("F29",Editor.GotoPageUp)

#	kh.BindKey("Home",Editor.GotoLineStart)
#	kh.BindKey("End",Editor.GotoLineEnd)
#	kh.BindKey("S-Home",Editor.SelectLineStart)
#	kh.BindKey("S-End",Editor.SelectLineEnd)
#
#	kh.BindKey("C-Home",Editor.GotoBeginningOfFile)
#	kh.BindKey("C-End",Editor.GotoEndOfFile)
#	kh.BindKey("C-S-Home",Editor.SelectBeginningOfFile)
#	kh.BindKey("C-S-End",Editor.SelectEndOfFile)

	# Deletion
	kh.BindKey("Backspace",Editor.Backspace)
	kh.BindKey("Del",Editor.Delete)
	kh.BindKey("C-d",Editor.Delete)
	kh.BindKey("Esc d",Editor.KillWord)
	kh.BindKey("C-Backspace",Editor.KillWord)
	kh.BindKey("Esc Backspace",Editor.BackwardKillWord)
	kh.BindKey("S-Backspace",Editor.BackwardKillWord)
	kh.BindKey("C-k",Editor.KillLine)

	# Macro definition and execution
	kh.BindKey("C-x (",kh.StartMacro)
	kh.BindKey("C-x )",kh.EndMacro)
	kh.BindKey("C-x e",kh.RunMacro)

	# Smart quoting
	kh.BindKey("Esc (",Editor.InsertTextAndSelect,"()",1)
	kh.BindKey("Esc [",Editor.InsertTextAndSelect,"[]",1)
	kh.BindKey("Esc {",Editor.InsertTextAndSelect,"{}",1)

	# WordExpansion
	kh.BindKey("Esc /", WordExpand.WordExpand)
	kh.BindKey("C-Tab", WordExpand.WordExpand)
	kh.BindKey("S-Tab", WordExpand.WordExpand)

	# Maro-fy a region
	kh.BindKey("C-t s", WordExpand.Slashify)
	kh.BindKey("C-t d", WordExpand.Slashify,'')

	# Sun keyboard
	kh.BindKey("F12",Editor.Redo)
	kh.BindKey("F14",Editor.Undo)
	kh.BindKey("F16",Editor.Copy)
	kh.BindKey("F18",Editor.Paste)
	kh.BindKey("F19",Editor.DoMenuCommand,CmdNo.cFIND)
	kh.BindKey("F20",Editor.Cut)


RegisterKeys(InitKeymap,"")
